home *** CD-ROM | disk | FTP | other *** search
- ;void change_character(strg,search,replace);
- ; unsigned char *strg,search,replace;
-
- EXTRN _memory_model:byte
- EXTRN _error_code:byte
-
- _TEXT SEGMENT BYTE PUBLIC 'CODE'
- ASSUME CS:_TEXT
- PUBLIC _change_character
- _change_character proc near
- push bp ;
- mov bp,sp ;set up stack frame
- push si ;
- push ds ;
- cmp _memory_model,0 ;near or far?
- jle begin ;jump if near
- inc bp ;else add 2 to BP
- inc bp ;
- begin: mov _error_code,0 ;assume char found
- cmp _memory_model,2 ;data near or far?
- jb L0 ;
- lds si,dword ptr[bp+4] ;SI pts to Strg
- inc bp ;add 2 to BP since dword ptr
- inc bp ;
- jmp short L00 ;
- L0: mov si,[bp+4] ;near case
- L00: sub dx,dx ;flags that a char found
- mov al,[bp+6] ;get replacement char
- mov ah,[bp+8] ;search character
- cmp byte ptr[si],0 ;test for null string
- je L3 ;
- L1: mov cl,[si] ;get a character
- cmp cl,0 ;end of string?
- je LX ;
- cmp cl,ah ;search char?
- jne L2 ;jump ahead if not
- mov [si],al ;else change char
- inc dx ;flag that a char found
- L2: inc si ;forward string ptr
- jmp short L1 ;go do next char
- LX: or dx,dx ;test if char found
- jnz L4 ;jump ahead if so
- L3: inc _error_code ;else 1 = char not found
- L4: pop ds ;
- pop si ;
- pop bp ;
- cmp _memory_model,0 ;quit
- jle quit ;
- db 0CBh ;RET far
- quit: ret ;RET near
- _change_character ENDP
- _TEXT ENDS
- END